<!-- 我卖出的 -->
<template>
	<view>
		<u-tabs
			class="u-flex-middle"
			lineColor="#f56c6c"
			:activeStyle="{
				color: '#303133',
				fontWeight: 'bold',
				transform: 'scale(1.05)'
			}"
			:inactiveStyle="{
				color: '#606266',
				transform: 'scale(1)'
			}"
			itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;"
			:list="typeList" @click="click"></u-tabs>
		<view>
			<!-- 空白页 -->
			<u-empty v-if="isEmpty === true && orderDataList.length === 0" :text="emptyText" mode="list"></u-empty>
			<goshop-order-list :data="orderDataList" :mode="1"></goshop-order-list>
			<u-loadmore
					:status="loadStatus" 
					:loading-text="loadingText" 
					:loadmore-text="loadmoreText" 
					:nomore-text="nomoreText" 
					loadingIcon="semicircle"
					@loadmore="getOrderPage"
				/>
		</view>
	</view>
</template>

<script>
	import {orderPage} from '@/common/http.api.js'
	export default {
		data() {
			return {
				//加载更多标志
				loadMoreFlag:false,
				isEmpty:false,
				orderDataList: [],
				emptyText:'',
				loadStatus: 'loadmore',
				loadingText: '',
				loadmoreText: '',
				nomoreText: '',
                typeList: [{
                    name: '',
					status:-1
                }, {
                    name: '',
					status:11
                }, {
                    name: '',
					status:10
                }, {
                    name: '',
					status:12
                }, {
				    name: '',
					status:13
				}, {
                    name: '',
					status:100
                }, {
                    name: '',
					status:14
                }],
				params: {
					pageNo: 1,
					status: -1, //全部
					pageSize: 10,
					tradeType:1,
					mode:1
				},			
			};
		},
		onReachBottom() {
			if(this.loadMoreFlag){
			  this.getOrderPage()
			}
		},
		onPullDownRefresh() {
			setTimeout(() => {
				this.params.pageNo = 1
				this.orderDataList = []
				this.getOrderPage()
				//关闭下拉刷新
				uni.stopPullDownRefresh()
			},2000)
		},
		onLoad(){
			this.getOrderPage()	
		},
		onShow(){
		  this.refresh();	
		},
		methods:{
			refresh(){
				this.emptyText = this.$t('common.empty.text');
				this.loadingText = this.$t('common.loading.text');
				this.loadmoreText = this.$t('common.loadmore.text');
				this.nomoreText = this.$t('common.nomore.text');
				this.typeList[0].name = this.$t('sold.all.text');
				this.typeList[1].name = this.$t('sold.tobedelivered.text');
				this.typeList[2].name = this.$t('sold.pendingpayment.text');
				this.typeList[3].name = this.$t('sold.pendingreceipt.text');
				this.typeList[4].name = this.$t('sold.comment.text');
				this.typeList[5].name = this.$t('sold.completed.text');
				this.typeList[6].name = this.$t('sold.aftersale.text');	
			},
			click(item) {
				console.log('item', item);
				this.params.status = this.typeList[item.index].status
				debugger
				this.getOrderPage();
			},
			getOrderPage(){
				this.loadStatus = 'loading';
				orderPage(this.params).then((res)=>{
					uni.stopPullDownRefresh()
					if(res.code === 0){
					  if(res.data.list.length === 0){
						this.isEmpty = true;
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  }else if (res.data.list.length < 10) {
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  } else {
						this.params.pageNo++;
						this.loadStatus = 'loading'
						this.loadMoreFlag = true;
					  }
					  if (this.params.pageNo > 1) {
						this.orderDataList = this.orderDataList.concat(res.data.list);
					  } else {
						this.orderDataList = res.data.list;
					  }
					}
				  }).catch(error=>{
					console.error(error)
				  })
			},
		}
	}
</script>

<style lang="scss">

</style>
